import HomeView from "../views/Home/index.vue";
import LoginView from "../views/Login/index.vue";

import ResultList from "@/views/Result/ResultList/index.vue";
import MyResult from "@/views/Result/MyResult/index.vue";
import IdeaList from "@/views/Idea/IdeaList/index.vue";
import MainView from "@/views/Main/index.vue";
import RouteAdd from "@/views/Route/RouteAdd/index.vue";
import RouteList from "@/views/Route/RouteList/index.vue";
import PersonalCenter from "@/views/PersonalCenter/index.vue";

var routes = [
  {
    path: "/home",
    // name: "home",
    component: HomeView,
    children: [
      { path: "", redirect: "/main" },
      { path: "/main", name: "main", label: "首页", component: MainView },
      {
        path: "/result/my",
        name: "myresult",
        label: "我的成绩",
        parent: { name: "result", label: "成绩管理" },
        component: MyResult,
      },
      {
        path: "/result/list",
        name: "resultlist",
        label: "成绩列表",
        parent: { name: "result", label: "成绩管理" },
        component: ResultList,
      },
      {
        path: "/result/submitResult",
        name: "submitResult",
        label: "新增成绩",
        parent: { name: "result", label: "成绩管理" },
        component: () => import("../views/Result/submitResult/index.vue"),
      },
      {
        path: "/result/resultAnalyse",
        name: "resultAnalyse",
        label: "成绩分析",
        parent: { name: "result", label: "成绩管理" },
        component: () => import("../views/Result/resultAnalyse/index.vue"),
      },
      {
        path: "/ notice/list",
        name: " noticeList",
        label: "公告列表",
        parent: { name: " notice", label: "公告管理" },
        component: () => import("@/views/Notice/NoticeList/index.vue"),
      },
      {
        path: "/idea/add",
        name: "ideaadd",
        label: "意见新增",
        parent: { name: "idea", label: "意见管理" },
        component: () => import("@/views/Idea/IdeaAdd/index.vue"),
      },
      {
        path: "/idea/list",
        name: "ideaList",
        label: "意见列表",
        parent: { name: "idea", label: "意见管理" },
        component: IdeaList,
      },
      {
        path: "/route/add",
        name: "routeadd",
        label: "路由新增",
        parent: { name: "route", label: "路由管理" },
        component: RouteAdd,
      },
      {
        path: "/route/list",
        name: "routelist",
        label: "路由列表",
        parent: { name: "route", label: "路由管理" },
        component: RouteList,
      },
      {
        path: "/personalcenter",
        name: "personalcenter",
        label: "个人中心",
        component: PersonalCenter,
      },
    ],
  },

  {
    path: "/login",
    name: "login",
    component: LoginView,
  },
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/404",
    name: "NodFont",
    component: () => import("../views/NodFont/index.vue"),
  },
  {
    path: "/:pathMatch(.*)*",
    name: "NodFont",
    component: () => import("../views/NodFont/index.vue"),
  },
];
//路由动态生成菜单
// console.log(routes);
const res = (routes) => {
  var items = routes[0].children || []; // 模拟实现 => 默认获取home路由 / (主页面下的) 路由配置
  // console.log(items);
  var mapMenu = {};
  items.forEach((item) => {
    if (item.path == "") return false; //默认显示的内容
    if (!item.parent) {
      mapMenu[item.name] = {
        path: item.path,
        name: item.name,
        label: item.label,
      }; //没有parent这个属性的路由就是一级菜单相关的信息
    } else {
      // 有parent => 二级路由（二级菜单）
      if (!mapMenu[item.parent.name]) {
        // 对应名字的一级导航是否生成  => 没有生成
        mapMenu[item.parent.name] = {
          name: item.parent.name,
          path: item.parent.name,
          label: item.parent.label,
          children: [
            {
              path: item.path,
              name: item.name,
              label: item.label,
            },
          ],
        };
      } else {
        //否则mapMenu[item.parent.name].children.push(一级路由的基本属性)
        mapMenu[item.parent.name].children.push({
          path: item.path,
          name: item.name,
          label: item.label,
        });
      }
    }
  });
  //Object.values
  return Object.values(mapMenu);
};
// console.log(res);
export let menus = res(routes);
// console.log(menus);

export default routes;
